var imgs = ['https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2042119437,2144065855&fm=26&gp=0.jpg',
'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=230587486,1047470314&fm=26&gp=0.jpg',
'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=640720754,981966893&fm=26&gp=0.jpg',
'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=4164344925,1357692930&fm=26&gp=0.jpg',
'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1876076772,3149796375&fm=26&gp=0.jpg',
'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3239502689,2147060440&fm=26&gp=0.jpg',
'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1871691577,622244938&fm=26&gp=0.jpg',
'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3021928222,423427470&fm=26&gp=0.jpg'];
var spans = document.getElementById("parent");
for (var i = 0; i<imgs.length;i++) {
	var span = document.createElement("span");
	span.className = "span1";
	span.num = i;
	span.innerHTML  = '<img src="' + imgs[i] +'" alt="">';
	spans.appendChild(span);	
}
var arr = [];
var span2 = document.querySelectorAll(".span1");
for (var i = 0; i < span2.length; i++) {
	span2[i].onclick = function (e) {
		var a  =  imgs[e.currentTarget.num];
		var f = [e.currentTarget.num];
		span2[e.currentTarget.num].className = "span1 red";
		setTimeout(function () {
			span2[f].className = "span1";
		},2000);
		arr.push(a);	
	}
}
$("#play").click(function() {
	var text = $("#content").val();
    var siteurl = sessionStorage.token;
    console.log(siteurl);	
	var pase = {"nickname":"代号"+ new Date().getTime(),"token":siteurl,"content":text,"portrait":arr[arr.length-1]};
	var  url = "http://39.105.222.9:8095/blog/add_blog/";
	$.post(url,pase,function(data) {
		if (data.result !=1) {
			alert("changpenga")
		}else {
			console.log(data.datas.nickname);
			alert("haha");
			if (arr.length >=1) {
				var qDiv = $("<div class = 'q'></div>");
				$(".abc").append(qDiv);
				var wDiv = $("<div class='w'></div>")
				qDiv.append(wDiv);
				console.log(data.datas.portrait);
				var img1 = $("<img src='"+data.datas.portrait+"'>");
				wDiv.append(img1);
				var eDiv = $("<div class='e'></div>");
				wDiv.append(eDiv);
				var rDiv = $("<div class='r'></div>");
				console.log(data.datas.nickname);
				rDiv.html(data.datas.nickname);/联系不起来/
				eDiv.append(rDiv);
				var span1 = $("<span class='t'></span>");
				var myDate = new Date;
		 		var mon = myDate.getMonth() + 1;
		 		var date = myDate.getDate();
				span1.html(mon+"月"+date+ "日");
				eDiv.append(span1);
				var span2 = $("<span class='y'></span>");
				var h1 = myDate.getHours();
				var min1 = myDate.getMinutes();
				span2.html(guolu(h1)+":"+guolu(min1));
				eDiv.append(span2);
				var iDiv = $("<div class='i'></div>");
				iDiv.html(text);
				eDiv.append(iDiv);
				var q2Div = $("<div class='q2'></div>");
				qDiv.append(q2Div);
				var span3 = $("<span></span>")
				span3.html("收藏");
				q2Div.append(span3);
				var span4 = $("<span></span>")
				span4.html("转发");
				q2Div.append(span4);
				var span5 = $("<span></span>")
				span5.html("评论");
				q2Div.append(span5);
				var span6 = $("<span></span>")
				span6.html("点赞");
				q2Div.append(span6);
				location.reload();
			}
		}
	})
});























